<!--suppress ALL -->
<template>
  <div class="page fireHazardDetail-container fireHazardDetail-page" data-page="fireHazardDetail" style="z-index: 2;">
    <div class="link-page-nav">
        <a href="#" class="link"  @click="$root.backToTab()">
            <i class="iconfont icon-zuo"></i>
        </a>
    </div>
    <div class="link-page-top" style="padding-bottom: 17px;">
        <div class="link-page-title">高危信号详情</div>
    </div>
    <div class="page-content" style="padding-bottom: 120px;">
        <div class="page-item">
          <div class="highDanger-item-border">
            <div class="highDanger-item-num" id="fireDetail-link-num_{{getNewId}}">0</div>
            <div class="highDanger-item-name">火情数量</div>
          </div>
          <div class="highDanger-detail-result-desc"><span id="highDanger-detail-result-isReset_{{getNewId}}">-</span><span id="highDanger-detail-result-isDel_{{getNewId}}">-</span></div>
          <div class="highDanger-detail-desc" id="highDanger-detail-desc_{{getNewId}}">-</div>
        </div>
        <div class="page-item">
          <div class="highDanger-tital-info">基础信息</div>
          <div class="highDanger-tital-item">
            <div class="highDanger-tital-left">单位名称</div>
            <div class="highDanger-tital-right" id="fireHazardDetail_unit_name_{{getNewId}}">-</div>
          </div>
          <div class="highDanger-tital-item">
            <div class="highDanger-tital-left">单位地址</div>
            <div class="highDanger-tital-right" id="fireHazardDetail_unit_address_{{getNewId}}">-</div>
          </div>
          <div class="highDanger-tital-item">
            <div class="highDanger-tital-left">安全责任人</div>
            <div class="highDanger-tital-right" id="safePeople_{{getNewId}}"></div>
          </div>
          <div class="highDanger-tital-item">
            <div class="highDanger-tital-left">安全管理人</div>
            <div class="highDanger-tital-right" id="setPeople_{{getNewId}}"></div>
          </div>
        </div>
        <div class="page-item">
            <div class="highDanger-tital-info">时间信息</div>
            <div class="highDanger-tital-item">
              <div class="highDanger-tital-left">发生时间</div>
              <div class="highDanger-tital-right" id="fireDetail-link-startTime_{{getNewId}}">-</div>
            </div>
            <div class="highDanger-tital-item">
              <div class="highDanger-tital-left">持续时间</div>
              <div class="highDanger-tital-right" id="fireDetail-link-intervalTime_{{getNewId}}">-</div>
            </div>
            <div class="highDanger-tital-item">
              <div class="highDanger-tital-left">复位时间</div>
              <div class="highDanger-tital-right" id="highDanger-detail-resetTime_{{getNewId}}">-</div>
            </div>
        </div>
        <div class="page-item">
            <div class="highDanger-tital-info">明细</div>
            <ul id="fireDetail-detail-fireList_{{getNewId}}" class="fireDetail-link-fireList">
                
            </ul>
        </div>
        <div class="page-item" id="history-detail_{{getNewId}}">
            <div class="highDanger-tital-info">处理记录</div>
            <div class="highDanger-tital-item">
              <div class="highDanger-tital-left">处理时间</div>
              <div class="highDanger-tital-right" id="fireHazardDetail-record-handlerTime_{{getNewId}}">-</div>
            </div>
            <div class="highDanger-tital-item">
              <div class="highDanger-tital-left">处理类型</div>
              <div class="highDanger-tital-right" id="fireHazardDetail-hand-type_{{getNewId}}">-</div>
            </div>
            <div class="highDanger-tital-item">
              <div class="highDanger-tital-left">处理人</div>
              <div class="highDanger-tital-right" id="fireHazardDetail-hand-name_{{getNewId}}">-</div>
            </div>
            <div class="highDanger-tital-item">
              <div class="highDanger-tital-left">备注</div>
              <div class="highDanger-tital-right" id="fireHazardDetail-hand-des_{{getNewId}}">-</div>
            </div>
        </div>
        <div class="page-item" id="fireDetail-video_{{getNewId}}" style="height:128px;display: none;">
            <div class="highDanger-goto-video-desc">想了解单位消控室是否有人值守？</div>
            <div class="highDanger-goto-video" id="highDanger-detail-video_{{getNewId}}">-</div>
        </div>
        <div class="page-item" id="fireDetail-quit_{{getNewId}}" style="height:128px;">
            <div class="rdsp-fix-botttom-deal" style="margin-top:8px;" @click="quitCancel">
                <span>立即处理</span>
            </div>
        </div>
      </div>
  </div>
</template>
<script>
    return {
        mounted() {
            var self = this;
            self.listId = self.$route.params.id;
            self.type = self.$route.params.type;
        },
        data: function () {
            return {
              listId:null,
              type:null,
              currentOrganizationId: null,
              getNewId: (new Date()).getTime()
            }
        },
        methods: {
          backToRefresh:function(){
            var self = this;
            self.showCurrantListMes();
          },
          quitCancel:function(){//立即处理
            var self = this;
            app.router.navigate("/fireHazardCancel/"+self.listId+"/");
          },
          getUnitInfo:function(){//单位信息
            var self = this;
            Dao.unitInfo({
              organizationId: self.currentOrganizationId
            }, function (data) {
                if(data.contacts&& data.contacts.length>0){
                  for(var i=0;i<data.contacts.length;i++){
                    //安全责任人
                    if(data.contacts[i].role==9){
                      $("#safePeople_"+self.getNewId).html(common.transNullundefinedToline(data.contacts[i].name) +" "+
                          `<a href="tel:`+data.contacts[i].phone+`" onclick="window.location='tel:`+data.contacts[i].phone+`'">`+data.contacts[i].phone+`</a>`);
                    }
                    //安全管理人
                    if(data.contacts[i].role==10){
                      $("#setPeople_"+self.getNewId).html(common.transNullundefinedToline(data.contacts[i].name) +" "+
                          `<a href="tel:`+data.contacts[i].phone+`" onclick="window.location='tel:`+data.contacts[i].phone+`'">`+data.contacts[i].phone+`</a>`);
                    }
                  }
                }
                $("#fireHazardDetail_unit_name_"+self.getNewId).html(common.transNullundefinedToline(data.name));
                $("#fireHazardDetail_unit_address_"+self.getNewId).html(common.transNullundefinedToline(data.address));
            });
          },
          showCurrantListMes:function(){
            var self = this;
            var $ = self.$$;

            //2019/06/24新增接口
            Dao.getHighRiskFireSignalById({
              id: self.listId
            }, function (data) {
                if(data){
                    self.currentOrganizationId = data.organizationId;
                    //处理记录
                    if(data.handlerStatus!=0){
                      $("#fireHazardDetail-record-handlerTime_"+self.getNewId).html(data.handlerTime);
                      $("#fireHazardDetail-hand-type_"+self.getNewId).html(data.handlerTypeName);
                      $("#fireHazardDetail-hand-des_"+self.getNewId).html(data.remarks);
                      $("#fireHazardDetail-hand-name_"+self.getNewId).html(data.handlerAccountName);
                      $("#highDanger-detail-result-isDel_"+self.getNewId).html("已处理");
                    }else{
                      $("#highDanger-detail-result-isDel_"+self.getNewId).html("未处理");
                    }
                    $("#highDanger-detail-desc_"+self.getNewId).html(common.transNullundefinedToline(data.selfDesc));
                    if(data.isReset==0){
                      $("#highDanger-detail-result-isReset_"+self.getNewId).html("未复位");
                      $("#highDanger-detail-resetTime_"+self.getNewId).html("当前未复位");
                    }else{
                      $("#highDanger-detail-result-isReset_"+self.getNewId).html("已复位");
                      $("#highDanger-detail-resetTime_"+self.getNewId).html(data.resetTime);
                    }
                    //报警明细
                    $("#fireDetail-detail-fireList_"+self.getNewId).empty();
                    if(data.detailAlert && data.detailAlert.length>0){
                        $("#fireDetail-link-num_"+self.getNewId).html(data.detailAlert.length);
                        for(var i=0;i<data.detailAlert.length;i++){
                          var url = "";
                          //多
                          if (userInfor.isMuilUnitUser == 1) {
                              url = '/eqmentMsg/'+data.detailAlert[i].fcFacilitiesId+'/';
                          } 
                          //单联网
                          else { 
                              url = '/eqmentMsg/' + data.detailAlert[i].fcFacilitiesId + '/';
                          }
                          $("#fireDetail-detail-fireList_"+self.getNewId).append(` <li class="highDanger-tital-item">
                              <a href="`+url+`" class="highDanger-tital-alarm" >
                                    <div class="item-title my-icon-tz">`+data.detailAlert[i].selfDesc+`</div>
                              </a>
                          </li>`);
                        }
                    }
                    $("#fireDetail-link-startTime_"+self.getNewId).html(data.startTime);
                    $("#fireDetail-link-intervalTime_"+self.getNewId).html(data.intervalTime);
                    if(data.handlerStatus==1){
                      $("#fireDetail-quit_"+self.getNewId).hide();
                      $("#history-detail_"+self.getNewId).show();
                    } else {
                      $("#history-detail_"+self.getNewId).hide();
                      //从历史记录点过来
                      if(self.type==1){
                        $("#fireDetail-quit_"+self.getNewId).hide();
                      }else{
                        if(data.isReset==0){
                          $("#fireDetail-quit_"+self.getNewId).show();
                        }else{
                          $("#fireDetail-quit_"+self.getNewId).hide();
                        }
                      }
                      //从处理完成界面back
                      if(1 === data.handType){
                        $("#fireDetail-quit_"+self.getNewId).hide();
                      }
                    }

                    self.getUnitInfo();
                    self.getUnitVedio();
                }
            });
          },
          getUnitVedio:function(){
            var self = this;
            var $ = self.$$;
            videoData = [];
            var organizationId = self.currentOrganizationId;
            Dao.getControlRoomInfo({
              userName:userInfor.accountName,
              orgId:organizationId
            },function(data){
              if(data && data.length>0){
                $("#fireDetail-video_"+self.getNewId).show();
                for (var i = 0; i < data.length; i++) {
                  videoData[data[i].video.id] = data[i].video;
                  //视频的情况
                  if(data.length==1){
                    $("#highDanger-detail-video_"+self.getNewId).html(`
                      <span id="goTo-see-video_`+self.getNewId+`" class="goTo-see-video"  data-id="`+data[0].video.id+`">立即查看消控室视频</span>
                    `);
                    $("#goTo-see-video_"+self.getNewId).click(function(event) {
                      var id = jQuery(event.currentTarget).attr("data-id");
                      self.playVedio(id);
                    });
                  }else{
                    $("#highDanger-detail-video_"+self.getNewId).html(`
                      <span id="goTo-see-video_`+self.getNewId+`" class="goTo-see-video"  data-id="`+organizationId+`">立即查看消控室视频</span>
                    `);
                    $("#goTo-see-video_"+self.getNewId).click(function(event) {
                      var organizationId = jQuery(event.currentTarget).attr("data-id");
                      app.router.navigate("/cotrolRoomVideo/"+organizationId+"/");
                    });
                  } 
               } 
              }else{
                $("#fireDetail-video_"+self.getNewId).hide();
              }
            },false);
          },
          formatFireTime : function(time){
              if(time){
                return time.replace("时","小时").replace("分","分钟");
              }
          },
          playVedio:function(id){
              var bean = videoData[id];
              var self = this;
              var videoBean  = {};
              videoBean.id = bean.id;
              videoBean.deviceId = bean.deviceId;
              videoBean.type = bean.type;
              videoBean.name = bean.name;
              videoBean.channel = bean.channel;
              videoBean.status = bean.status;
              videoBean.picUrl = bean.picUrl;
              videoBean.isOnline = bean.isOnline;
              videoBean.isConcem = bean.isConcem == null?0:bean.isConcem;
              Dao.getAuthList({
                 userName:userInfor.accountName,
                 deviceId:appKeyObj.deviceId,
                 organizationId:self.currentOrganizationId,
                 equiptType:bean.type,
                 orgCode:userInfor.org.orgCode,
                 authId: bean.authId
              },function(data) {
                  var videoKeyBean = data[0];
                  native.openVideo(JSON.stringify(videoKeyBean),JSON.stringify(videoBean));
              });
          }
        },
        on:{
           pageInit:function () {
               var self = this;
               self.showCurrantListMes();
           },
        }
    }
</script>
<style scoped>
  .page-item{
    margin: 0px 20px 30px 20px;
  }
</style>